home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 012 / Mike's Folder / Hacker's Hangout < prev    next >
Encoding:
Text File  |  1993-12-01  |  5.0 KB  |  92 lines  |  [TEXT/ttxt]

  1. Hacker's Hangout
  2. ================
  3. Copyright © 1993 by Celestin Company
  4. All rights reserved.
  5.  
  6. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  7.  
  8. Introduction
  9. ------------
  10. Haven't you always wanted to take the contents of a text file and write them to another text file, only backwards? Well, even if you've never even dreamed of doing this, here's your chance. This hack will take any size text file and create a mirror version of it.
  11.  
  12. To perform this hack, we take advantage of the GetEOF function, to find out how long the file is. We also use the File Set Position command to set the file marker for the source file where we want it to be.
  13.  
  14. Instructions - Put the module called 'Backwards' in your Module Folder, which is in the same location as the MicroPhone application. If you do not have a Module Folder, create one. Open any MicroPhone settings document. Create the following script:
  15.  
  16.   Set Variable * Backwards from TEXT File Dialog "'File to Convert?'"
  17.   If Expression "Length(Backwards) > 0"
  18.     Do Script "'Main','Backwards'"
  19.   End If
  20.  
  21. That's it.
  22.  
  23. Theory
  24. ------
  25. So, what's behind this hack? Let's take a quick look at the scripts in Backwards. Here are the scripts in the Backwards module:
  26.  
  27. Main
  28. Backwards
  29. FileOpen
  30. FileClose
  31. FileReplace
  32. FileInfoGet
  33. FileInfoSet
  34.  
  35. Main - this script simply calls the script Backwards. It is used to provide a single entry point into the module. This way, you don't have to know the name of a particular script. Just call the main script in any of the modules that have been provided with Open Mike and they will do the right thing.
  36.  
  37. Backwards - This script does the work of converting the file, by calling several other scripts. First, it calls FileInfoGet to get the type and creator of the source file. Then, it calls FileOpen to open the source and destination files. Next, it repeatedly reads one character from the source file and writes it to the destination file until the entire source file has been processed. Then, it calls FileClose. Finally, it calls FileReplace, to replace the source file with the new file it has created:
  38.  
  39. If Expression "Exists(Backwards)"
  40.   Do Script * "'FileInfoGet'"
  41.   If Success
  42.     Do Script * "'FileOpen'"
  43.     If Success
  44.       Dialog Install "'Converting, please wait…'"
  45.       Set Variable * Backwardsn from Expression "GetEOF(Backwards)"
  46.       While Expression "Backwardsn > 0"
  47.         Set Variable * Backwardsn from Expression "Backwardsn - 1"
  48.         File * Set Position at Offset "Backwards,Backwardsn"
  49.         File * Write "Backwardsb,ReadCh(Backwards)"
  50.       End While
  51.       Delete Variable Backwardsn
  52.       Do Script * "'FileClose'"
  53.       Do Script * "'FileInfoSet'"
  54.       Do Script * "'FileReplace'"
  55.       If Success
  56.         Return Success
  57.       Else
  58.         Remark "--- could not replace old source file"
  59.         Return Failure
  60.       End If
  61.     Else
  62.       Remark "--- could not open files"
  63.       Do Script * "'FileClose'"
  64.       Return Failure
  65.     End If
  66.   Else
  67.     Remark "--- could not get file information"
  68.     Return Failure
  69.   End If
  70. Else
  71.   Remark "--- variable Backwards does not exist"
  72.   Return Failure
  73. End If
  74.  
  75. FileOpen - this script opens the source and destination files. It gives the destination the same name as the source, with '.b' appended to the name. If the name is greater than 31 characters, it concatenates the name until it equals 31 characters. If any problems are encountered, it returns failure. Otherwise, it returns success.
  76.  
  77. FileClose - this script closes the source and destination files.
  78.  
  79. FileReplace - this script replaces the old source file with the newly created file. If any problems are encountered, it returns failure. Otherwise, it returns success.
  80.  
  81. FileInfoGet - this script gets the file information for the source file using the FileTYPE and FileCRTR functions. These values are stored in the variables myFileTYPE and myFileCRTR.
  82.  
  83. FileInfoSet - this script sets the file information for the new file using the stored TYPE and CREATOR information in the myFileTYPE and myFileCRTR variables.
  84.  
  85. Where To Go From Here
  86. ---------------------
  87. Backwards is an ideal candidate for an XCMD, because all we are dealing with are a source and destination file. MicroPhone scripts are powerful and flexible, but when you need to process a huge file, maybe a 20 megabyte session file from your frenzied weekend, you might find MicroPhone a tad slow. Maybe we'll convert Backwards to an XCMD in a future issue of Open Mike.
  88.  
  89. Important Note
  90. --------------
  91. Hacks are not guaranteed to work, although there is no reason why they shouldn't work. Every care has been taken to make sure that they work on the hacker's machine, but they may do other things on your machine. Of course, if you encounter problems, you may feel free to tweak the hack to run on your machine.
  92.